import {createApp} from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import router from "./router"; // 添加路由router引入
import './assets/static/icons/iconfont/iconfont.css'
import './assets/static/css/startcampusfont.css'
import './assets/static/icons/iconfont/iconfont.js'
import {getToken, setUserInfo} from "@/utils/auth";
import {info} from "@/api/admin/admin";

const app = createApp(App)
app.use(ElementPlus)
app.use(router)
app.mount("#app")
router.beforeEach((to, from, next) => {
    if (to.path === '/login' || to.path === '/404') {
        next()
    } else {
        const token = getToken()
        if (!token) {
            next({
                path: '/login'
            })
        } else {
            info().then(res => {
                setUserInfo(res.data)
            })
            next()
            // const roleEncodes = to.meta.roleEncode
            // const userRoleEncode = userInfo.encode
            // if (roleEncodes.includes(userRoleEncode)) {
            //     next()
            // } else {
            //     next({
            //         path: '/404'
            //     })
            // }
        }
    }
})